
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
  <title>FindFLEX &mdash; CMake 3.16.5 Documentation</title>

    <link rel="stylesheet" href="../_static/cmake.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    
    <link rel="shortcut icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="FindFLTK2" href="FindFLTK2.html" />
    <link rel="prev" title="FindEXPAT" href="FindEXPAT.html" />
  
 

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="FindFLTK2.html" title="FindFLTK2"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="FindEXPAT.html" title="FindEXPAT"
             accesskey="P">previous</a> |</li>
  <li>
    <img src="../_static/cmake-logo-16.png" alt=""
         style="vertical-align: middle; margin-top: -2px" />
  </li>
  <li>
    <a href="https://cmake.org/">CMake</a> &#187;
  </li>
  <li>
    <a href="../index.html">3.16.5 Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-modules.7.html" accesskey="U">cmake-modules(7)</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="findflex">
<span id="module:FindFLEX"></span><h1>FindFLEX<a class="headerlink" href="#findflex" title="Permalink to this headline">¶</a></h1>
<p>Find Fast Lexical Analyzer (Flex) executable and provides a macro
to generate custom build rules</p>
<p>The module defines the following variables:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>FLEX_FOUND - True is flex executable is found
FLEX_EXECUTABLE - the path to the flex executable
FLEX_VERSION - the version of flex
FLEX_LIBRARIES - The flex libraries
FLEX_INCLUDE_DIRS - The path to the flex headers
</pre></div>
</div>
<p>The minimum required version of flex can be specified using the
standard syntax, e.g.  <span class="target" id="index-0-command:find_package"></span><a class="reference internal" href="../command/find_package.html#command:find_package" title="find_package"><code class="xref cmake cmake-command docutils literal notranslate"><span class="pre">find_package(FLEX</span> <span class="pre">2.5.13)</span></code></a></p>
<p>If flex is found on the system, the module provides the macro:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>FLEX_TARGET(Name FlexInput FlexOutput
            [COMPILE_FLAGS &lt;string&gt;]
            [DEFINES_FILE &lt;string&gt;]
            )
</pre></div>
</div>
<p>which creates a custom command to generate the <code class="docutils literal notranslate"><span class="pre">FlexOutput</span></code> file from
the <code class="docutils literal notranslate"><span class="pre">FlexInput</span></code> file.  If <code class="docutils literal notranslate"><span class="pre">COMPILE_FLAGS</span></code> option is specified, the next
parameter is added to the flex command line. If flex is configured to
output a header file, the <code class="docutils literal notranslate"><span class="pre">DEFINES_FILE</span></code> option may be used to specify its
name. Name is an alias used to get details of this custom command.
Indeed the macro defines the following variables:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>FLEX_${Name}_DEFINED - true is the macro ran successfully
FLEX_${Name}_OUTPUTS - the source file generated by the custom rule, an
alias for FlexOutput
FLEX_${Name}_INPUT - the flex source file, an alias for ${FlexInput}
FLEX_${Name}_OUTPUT_HEADER - the header flex output, if any.
</pre></div>
</div>
<p>Flex scanners often use tokens defined by Bison: the code generated
by Flex depends of the header generated by Bison.  This module also
defines a macro:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>ADD_FLEX_BISON_DEPENDENCY(FlexTarget BisonTarget)
</pre></div>
</div>
<p>which adds the required dependency between a scanner and a parser
where <code class="docutils literal notranslate"><span class="pre">FlexTarget</span></code> and <code class="docutils literal notranslate"><span class="pre">BisonTarget</span></code> are the first parameters of
respectively <code class="docutils literal notranslate"><span class="pre">FLEX_TARGET</span></code> and <code class="docutils literal notranslate"><span class="pre">BISON_TARGET</span></code> macros.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>====================================================================
Example:
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>find_package(BISON)
find_package(FLEX)
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>BISON_TARGET(MyParser parser.y ${CMAKE_CURRENT_BINARY_DIR}/parser.cpp)
FLEX_TARGET(MyScanner lexer.l  ${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp)
ADD_FLEX_BISON_DEPENDENCY(MyScanner MyParser)
</pre></div>
</div>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span> include_directories(${CMAKE_CURRENT_BINARY_DIR})
 add_executable(Foo
    Foo.cc
    ${BISON_MyParser_OUTPUTS}
    ${FLEX_MyScanner_OUTPUTS}
 )
 target_link_libraries(Foo ${FLEX_LIBRARIES})
====================================================================
</pre></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="FindEXPAT.html"
                        title="previous chapter">FindEXPAT</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="FindFLTK2.html"
                        title="next chapter">FindFLTK2</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/module/FindFLEX.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="FindFLTK2.html" title="FindFLTK2"
             >next</a> |</li>
        <li class="right" >
          <a href="FindEXPAT.html" title="FindEXPAT"
             >previous</a> |</li>
  <li>
    <img src="../_static/cmake-logo-16.png" alt=""
         style="vertical-align: middle; margin-top: -2px" />
  </li>
  <li>
    <a href="https://cmake.org/">CMake</a> &#187;
  </li>
  <li>
    <a href="../index.html">3.16.5 Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-modules.7.html" >cmake-modules(7)</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2000-2019 Kitware, Inc. and Contributors.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.1.2.
    </div>
  </body>
</html>